home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
awe2-0_1.lha
/
awe2-0.1
/
Src
/
RCS
/
SharedMalloc.h,v
< prev
next >
Wrap
Text File
|
1988-09-18
|
3KB
|
121 lines
head 1.1;
access ;
symbols ;
locks ; strict;
comment @ * @;
1.1
date 88.09.18.16.42.15; author grunwald; state Exp;
branches ;
next ;
desc
@@
1.1
log
@Initial revision
@
text
@#ifndef SharedMalloc_h
#define SharedMalloc_h
char *malloc( unsigned );
void free(char *);
// char *realloc(char *, unsigned);
//
// calloc and cfree are defined in terms of malloc.
// alloca allocates space from the current stack.
//
#include "assert.h"
#include "HardSpinLock.h"
//
// Allocator.h: based loosely on...
//
// malloc.c (Caltech) 2/21/82
// Chris Kingsley, kingsley@@cit-20.
//
// $Header: Allocator.h,v 1.5 88/09/16 20:51:37 russo Exp $
//
//
//
// Below is a allocator sbuclass based loosely on..
//
// malloc.c (Caltech) 2/21/82
// Chris Kingsley, kingsley@@cit-20.
//
// This is a very fast storage allocator. It allocates blocks of a small
// number of different sizes, and keeps free lists of each size. In this
// implementation, the available sizes are 2^n-4 (or 2^n-12) bytes long.
//
//
// The overhead on a block is at least 4 bytes. When free, this space
// contains a pointer to the next free block, and the bottom two bits must
// be zero. When in use, the first byte is set to MAGIC, and the second
// byte is the size index. The remaining bytes are for alignment.
// If range checking is enabled and the size of the block fits
// in two bytes, then the top two bytes hold the size of the requested block
// plus the range checking words, and the header word MINUS ONE.
//
union overhead {
union overhead * ov_next; // when free
struct {
unsigned char ovu_magic; // magic number
unsigned char ovu_index; // bucket #
unsigned short ovu_size; // actual block size
unsigned int ovu_rmagic; // range magic number
} ovu;
};
#define ov_magic ovu.ovu_magic
#define ov_index ovu.ovu_index
#define ov_size ovu.ovu_size
#define ov_rmagic ovu.ovu_rmagic
#define MAGIC 0xff /* magic # on accounting info */
#define RMAGIC 0x55555555 /* magic # on range info */
#define RSLOP sizeof( unsigned int )
//
// nextf[i] is the pointer to the next free block of size 2^(i+3). The
// smallest allocatable block is 8 bytes. The overhead information
// precedes the data area returned to the user.
//
int const NumberOfBuckets = 30;
class BucketAllocator {
protected:
union overhead * nextf[ NumberOfBuckets ];
HardSpinLock bucketLock[ NumberOfBuckets ];
HardSpinLock topLock;
char * top;
char sbrkDisabled;
char initialized;
int morecore( int bucket );
void initialize();
public:
BucketAllocator();
~BucketAllocator();
void * allocate( unsigned nbytes );
void free( void * cp );
void disableFurtherBreaks();
};
extern BucketAllocator HardwareMemoryAllocator;
#endif /* SharedMalloc_h */
@